package com.nbjtjc.safe.qrCode;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.nbjtjc.safe.mapper.danger.DangerInspectMapper;
import com.nbjtjc.safe.mapper.sys.SysDeptMapper;
import com.nbjtjc.safe.model.danger.DangerInspect;
import com.nbjtjc.safe.model.sys.SysDept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @auther guqianbin
 * @date 2018/10/16 16:20
 **/
@Service
public class QrCodeService {

    @Autowired
    private DangerInspectMapper dangerInspectMapper;

    @Autowired
    private SysDeptMapper sysDeptMapper;

    public String getQrCodeJsonStr(int inspectId) {
        Map<String,Object> data=new HashMap<>();
        DangerInspect dangerInspect = dangerInspectMapper.selectByPrimaryKey(inspectId);
        if(ObjectUtil.isNull(dangerInspect)){
            data.put("success",false);
        }
        data.put("inspectId",inspectId);
        SysDept dept=sysDeptMapper.selectByPrimaryKey(dangerInspect.getDeptId());
        if(ObjectUtil.isNotNull(dept)){
            data.put("deptName",dept.getName());
            data.put("deptId",dept.getId());
        }
        SysDept company=sysDeptMapper.selectByPrimaryKey(dangerInspect.getCompanyId());
        if(ObjectUtil.isNotNull(company)){
            data.put("companyName",company.getName());
            data.put("companyId",company.getId());
        }
        return JSON.toJSONString(data);
    }
}
